import sun.awt.image.ImageWatched;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        MyBloomFilter myBloomFilter = new MyBloomFilter();

        myBloomFilter.add("hello");
        myBloomFilter.add("hello1");
        myBloomFilter.add("hello2");
        myBloomFilter.add("world");
        myBloomFilter.add("no");
        myBloomFilter.add("yes");

        System.out.println(myBloomFilter.contains("hello"));
        System.out.println(myBloomFilter.contains("hello2"));
        System.out.println(myBloomFilter.contains("hello3"));
        System.out.println(myBloomFilter.contains("haha"));
    }
    public static void main17(String[] args) {
        int[] array = {4, 2, 6, 1, 3, 5, 7, 14, 16, 15, 130};

        MyBitSet myBitSet = new MyBitSet(16);
        for(int i = 0; i < array.length; i++){
            myBitSet.set(array[i]);
        }

        for(int i = 0; i < myBitSet.elem.length; i++){
            for(int j = 0; j < 8; j++){
                if(((myBitSet.elem[i] >> j) & 1) == 1){
                    System.out.print(8 * i + j + " ");
                }
            }
        }

//        System.out.println(myBitSet.getUsedSize());
//        System.out.println(myBitSet.get(15));
//        myBitSet.reset(15);
//        System.out.println(myBitSet.get(15));

//        System.out.println(myBitSet.get(190));
    }
    public static void main16(String[] args) {
        RBTree rbTree = new RBTree();
        int[] array = {4, 2, 6, 1, 3, 5, 15, 7, 16, 14};

        for(int i = 0; i < array.length; i++){
            rbTree.insert(array[i]);
        }

        int blackNum = 0;
        RBTree.RBTreeNode cur = rbTree.root;
        while(cur != null){
            if(cur.color == COLOR.BLACK){
                blackNum++;
            }
            cur = cur.right;
        }
        System.out.println("红黑树最右边路径上的黑色节点个数: " + blackNum);
        System.out.println(rbTree.isRBTree(rbTree.root, 0, blackNum));

        rbTree.inOrder(rbTree.root);
    }
    public static void main15(String[] args) {
//        int[] array = {16, 3, 7, 11, 9, 26, 18, 14, 15};
//        int[] array = {4, 2, 6, 1, 3, 5, 15, 7, 16, 14};
        int[] array = {30, 20, 90, 60, 180, 40};
        AVLTree avlTree = new AVLTree();

        for(int i = 0; i < array.length; i++){
            avlTree.insert(array[i]);
        }

        avlTree.inOrder(avlTree.root);
        System.out.println();

        int height = avlTree.getHeight(avlTree.root);
        if(height == -1){
            System.out.println("不是二叉平衡树");
        }else{
            System.out.println("是二叉平衡树");
        }
    }

    public static void main14(String[] args) {
        HashBuckUpgrade<Person, String> hashBuck = new HashBuckUpgrade();
        HashSet<Integer> set = new HashSet<>();
        Person p1 = new Person(1);
        Person p2 = new Person(2);
        Person p3 = new Person(3);
        Person p4 = new Person(4);
        Person p5 = new Person(5);
        Person p6 = new Person(6);
        Person p7 = new Person(7);
        Person p8 = new Person(8);

        Person p11 = new Person(11);
        Person p22 = new Person(22);
        Person p33 = new Person(33);
        Person p44 = new Person(44);
        Person p55 = new Person(55);
        Person p66 = new Person(66);
        Person p77 = new Person(77);
        Person p88 = new Person(88);

        hashBuck.put(p1, "zhangsan");
        hashBuck.put(p2, "lisi");
        hashBuck.put(p3, "wangwu");
        hashBuck.put(p4, "zhaoliu");
        hashBuck.put(p5, "tianqi");
        hashBuck.put(p6, "ergouzi");
        hashBuck.put(p7, "lageda");
        hashBuck.put(p8, "mianshiguan");

        hashBuck.put(p11, "laomo");
        hashBuck.put(p22, "sanmao");
        hashBuck.put(p33, "choudan");
        hashBuck.put(p44, "lvbu");
        hashBuck.put(p55, "maomi");
        hashBuck.put(p66, "xiaogou");
        hashBuck.put(p77, "bajie");
        hashBuck.put(p88, "yingyinguai");

        System.out.println();

        System.out.println(hashBuck.get(p8));
    }
    public static void main13(String[] args) {
        HashBuck hashBuck = new HashBuck();

        hashBuck.put(1, 1);
        hashBuck.put(3, 3);
        hashBuck.put(13, 13);
        hashBuck.put(5, 1);
        hashBuck.put(6, 1);
        hashBuck.put(16, 1);
        hashBuck.put(8, 888);
        hashBuck.put(18, 1);

        System.out.println();

        System.out.println(hashBuck.get(8));
    }
    public static void main12(String[] args) {
        BinarySearchTree binarySearchTree = new BinarySearchTree();
        binarySearchTree.insert(3);
        binarySearchTree.insert(6);
        binarySearchTree.insert(8);
        binarySearchTree.insert(5);
        System.out.println();
        binarySearchTree.remove(6);
        System.out.println();
    }
    public static void main11(String[] args) {
        int[] array1 = new int[10_0000];
        int[] array2 = new int[10_0000];
        int[] array3 = new int[10_0000];

        orderArray(array1);
        reverseOrderArray(array2);
        randomArray(array3);

        testInsertSort(array1);
        testInsertSort(array2);
        testInsertSort(array3);

        testShellSort(array1);
        testShellSort(array2);
        testShellSort(array3);

        testSelectSort(array1);
        testSelectSort(array2);
        testSelectSort(array3);

        testHeapSort(array1);
        testHeapSort(array2);
        testHeapSort(array3);

        testBubbleSort(array1);
        testBubbleSort(array2);
        testBubbleSort(array3);
    }

    public static void testInsertSort(int[] array){
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序：" + (endTime - startTime));
    }

    public  static void testShellSort(int[] array){
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序：" + (endTime - startTime));
    }

    public static void testSelectSort(int[] array){
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序：" + (endTime - startTime));
    }

    public static void testHeapSort(int[] array){
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序：" + (endTime - startTime));
    }

    public static void testBubbleSort(int[] array){
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序：" + (endTime - startTime));
    }

    public static void orderArray(int[] array){
        for(int i = 0; i < array.length; i++){
            array[i] = i;
        }
    }

    public static void reverseOrderArray(int[] array){
        int n = array.length;
        for(int i = 0; i < n; i++){
            array[i] = n - 1 - i;
        }
    }

    public static void randomArray(int[] array){
        Random random = new Random();
        int n = array.length;
        for(int i = 0; i < array.length; i++){
            array[i] = random.nextInt(n);
        }
    }
    public static void main10(String[] args) {
        int[] array = { 27,15,19,18,28,34,65,49,25,37 };
        //Sort.insertSort(array);
        //Sort.shellSort(array);
        //Sort.selectSort(array);
        //Sort.heapSort(array);
        //Sort.bubbleSort(array);
        //Sort.quickSort(array);
        //Sort.quickSortNor(array);
        System.out.println(Arrays.toString(array));
        //Sort.mergeSort(array);
        //Sort.mergeSortNor(array);
        Sort.countSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main9(String[] args) {
        int[] array = { 27,15,19,18,28,34,65,49,25,37 };
        Heap heap = new Heap(array);
        heap.createHeap();
        //heap.offer(80);
        int t = heap.poll();
        System.out.println(t);
    }
    public static void main8(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();
//        int ret = binaryTree.size(root);
//        System.out.println(ret);
//        System.out.println(binaryTree.getLeafNodeCount(root));
//        System.out.println(binaryTree.getKLevelNodeCount(root, 2));
//        System.out.println(binaryTree.getHeight(root));
//        BinaryTree.TreeNode ret2 = binaryTree.find(root, 3);
//        binaryTree.levelOrder(root);
//        List<List<BinaryTree.TreeNode>> ret = binaryTree.levelOrder2(root);
//        System.out.println();
        System.out.println(binaryTree.isCompleteTree(root));
    }
    public static void main7(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();
        binaryTree.preOrder(root);
        System.out.println();
        binaryTree.inOrder(root);
        System.out.println();
        binaryTree.postOrder(root);
        System.out.println();
    }
    public static void main6(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.offer(1);
        myQueue.offer(2);
        myQueue.offer(3);
        myQueue.offer(4);
        myQueue.poll();
        myQueue.poll();
        myQueue.poll();
        myQueue.poll();
    }
    public static void main5(String[] args) {
        MySingleList list = new MySingleList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
//        list.reversePrint(list.head);
        list.reversePrintByStack(list.head);
    }
    public static void main4(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(1);
        myStack.push(2);
        myStack.push(3);
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
        System.out.println(myStack.pop());
    }
    public static void main3(String[] args) {
        MyLinkedList list = new MyLinkedList();
        list.addLast(1);
        list.addLast(1);
        list.addLast(1);
        list.addLast(1);
//        list.addLast(5);
//        list.addLast(6);
//        list.addLast(1);
        list.display();
//        list.addIndex(0, 111);
//        list.display();
//        list.addIndex(8, 888);
//        list.display();
//        list.addIndex(2, 222);
//        list.display();
//        list.remove(1);
//        list.removeAll(1);
        list.clear();
        list.display();
    }
    public static void main2(String[] args) {
        String str1 = "welcome to cvte";
        String str2 = "come";
        char[] s1 = str1.toCharArray();
        char[] s2 = str2.toCharArray();
        List<Character> list = new ArrayList<>();
        for(char ch : s2) list.add(ch);
        StringBuilder ret = new StringBuilder();
        for(char ch : s1){
            if(!list.contains(ch)){
                ret.append(ch);
            }
        }
        System.out.println(ret.toString());
    }
    public static void main1(String[] args) {
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        List<Integer> list = new ArrayList<>(set);
        list.add(3);
    }
}
